// +----------------------------------------------------------------------
// | appbar
// +----------------------------------------------------------------------

import 'package:flutter/material.dart';
import 'package:qgchat/common/global/global.dart';

// ignore: must_be_immutable
class AppbarCustom extends StatefulWidget implements PreferredSizeWidget {

  AppbarCustom(this.title, {
    Key key,
    this.rightText,
    this.elevation = 1.0,
    this.rightOnPressed,
  }) : super(key:key);

  final String title;
  final String rightText;
  final double elevation;
  dynamic rightOnPressed;


  @override
  _AppbarCustomState createState() => _AppbarCustomState();

  @override
  // TODO: implement preferredSize
  Size get preferredSize => Size.fromHeight(px(100));
}

class _AppbarCustomState extends State<AppbarCustom> {

  Widget _getRightFlatButton() {
    if (widget.rightText != null) {
      return FlatButton(
        padding: EdgeInsets.all(px(0)),
        onPressed: widget.rightOnPressed,
        child: Text(
          widget.rightText,
          style: TextStyle(
            fontSize: px(34),
            color: col('5640c6'),
          ),
        ),
      );
    } else {
      return Container();
    }
  }

  @override
  Widget build(BuildContext context) {
    return AppBar(
      leading: new IconButton(
        icon: new Icon(Icons.arrow_back_ios, color: Colors.black, size: px(36),),
        onPressed: () => Navigator.of(context).pop(),
      ),
      centerTitle: true,
      elevation: widget.elevation,
      title: Text(
        widget.title,
        style: TextStyle(
          fontSize: px(34),
          color: col('000000'),
          fontWeight: FontWeight.bold
        ),
      ),
      actions: <Widget>[
        Center(
          child: Container(
            width: px(110),
            height: px(100),
            child: _getRightFlatButton()
          ),
        )
      ],
    );
  }
}
